import 'package:flutterapp/mobx/model/tip.dart';
import 'package:flutterapp/mobx/model/user.dart';
import 'package:mobx/mobx.dart';

part 'account_store.g.dart';

class AccountStore = _AccountStore with _$AccountStore;

abstract class _AccountStore with Store {
  ReactionDisposer _when;

  _AccountStore() {
    _when = when((_) => count > 5, () {
      print('hehe$count');
    });
  }

  @observable
  User user;
  @observable
  Tip tip;
  @observable
  int state = 0;
  @observable
  int count = 0;
  @observable
  ObservableList<int> list = ObservableList.of([1]);

  String pureField;

  void increment() {
    count++;
    print('when is dispose ${_when.reaction.isDisposed}');
  }

  void addList(int item) {
    list.add(item);
  }

  @action
  Future<void> loadUser() async {
    if (state == 1) return;
    state = 1;
    await Future.delayed(Duration(seconds: 2));
    state = 2;
  }

  @action
  setUser(User user) {
    this.user = user;
  }

  login(String name) async {}
}

class Ta = _Ta with _$Ta;

abstract class _Ta with Store {}
